# _*_ coding : utf-8 _*_
# @Time: 2024/10/15 16:20
# @Author : 石文帅	
# @File : testbase03知识库
# @Project : python_slfh

from server.slfhWorkbench import *
from selenium.webdriver.chrome.service import Service


class test(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.wd = webdriver.Chrome(service=Service(driver_path))
        cls.wd.get(url_path)
        cls.wd.maximize_window()
        login(cls.wd)

    @classmethod
    def tearDownClass(cls):

        cls.wd.quit()
        log.info('----------------------------------------------------------')

    def testbase03知识库(self):
        """
        知识库
        :return:
        """
        log.info('进入知识库')
        locate_click(self.wd, homepage['知识库'])
        locate_click(self.wd, knowledge['新增知识库'])
        if element_exist(self.wd, knowledge['新增编辑弹框']):
            log.info('新增知识库弹框成功打开')
            edit_knowledge(self.wd)
            assert_str_element(self.wd, '* 请输入类别名称', knowledge['名称错误提示'])
            assert_str_element(self.wd, '* 请输入类别描述', knowledge['描述错误提示'])
            assert_str_element(self.wd, '* 请选择类别图片', knowledge['模版未选提示'])

            edit_knowledge(self.wd, '测试', '测试')
            assert_str_element(self.wd, '* 描述内容3-20字', knowledge['名称错误提示'])
            assert_str_element(self.wd, '* 描述内容5-50字', knowledge['描述错误提示'])
            assert_str_element(self.wd, '* 请选择类别图片', knowledge['模版未选提示'])

            edit_knowledge(self.wd, '测试知识库', '测试知识库的描述', '模版1-2')
            assert_false(element_exist(self.wd, knowledge['新增编辑弹框']))
            log.info('新增知识库成功')
        else:
            raise log.info('新增知识库弹窗打开失败')

        log.info('验证新增的模版图片和知识库名称是否对应一致')
        assert_img_locate(self.wd, '知识库图片1-2.png', knowledge['测试知识库图片'])

        log.info('编辑知识库,悬停后点击')
        mouse_hover(self.wd, knowledge['测试知识库图片'])
        locate_click(self.wd, knowledge['测试知识库编辑'])
        edit_knowledge(self.wd, '测试知识库2', '测试知识库描述', '模版2-1')

        log.info('验证编辑的模版图片和知识库名称是否对应一致')
        assert_img_locate(self.wd, '知识库图片2-1.png', knowledge['测试知识库2图片'])

        log.info('删除-悬停后点击')
        mouse_hover(self.wd, knowledge['测试知识库2图片'])
        locate_click(self.wd, knowledge['测试知识库2删除'])
        locate_click(self.wd, knowledge['删除确认'])
        log.info('删除验证')
        assert_false(element_exist(self.wd, knowledge['测试知识库2图片']))

        log.info('验证有内容无法删除')
        mouse_hover(self.wd, knowledge['生活常识图片'])
        locate_click(self.wd, knowledge['生活常识删除'])
        locate_click(self.wd, knowledge['删除确认'])
        assert_str_element(self.wd, '该分类下存在子分类或文章，不支持删除', knowledge['报错提示'])
        assert_true(element_exist(self.wd, knowledge['生活常识图片']))














